package com.taobao.txc.resourcemanager;

import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.b.c;
import com.taobao.txc.common.c.B;
import com.taobao.txc.common.c.f;
import com.taobao.txc.common.c.g;
import com.taobao.txc.common.c.h;
import com.taobao.txc.common.c.i;
import com.taobao.txc.resourcemanager.mt.MtResourceManager;
import java.util.List;

public class j
  implements com.taobao.txc.a.a.a
{
  private a a;
  private a b;
  private b c;
  private static final LoggerWrap d = LoggerInit.logger;
  private MtResourceManager e;
  
  public void a(MtResourceManager paramMtResourceManager)
  {
    this.e = paramMtResourceManager;
  }
  
  public void a(long paramLong, String paramString, Object paramObject)
  {
    d.info("onMessage:" + paramObject);
    if (Thread.currentThread().getName().startsWith("nio")) {
      d.a(com.taobao.txc.common.b.b.ak.bd, "onMessage goto nio thread", new RuntimeException("shouldn't in nio thread."));
    }
    if ((paramObject instanceof f)) {
      c(paramLong, paramString, paramObject);
    } else if ((paramObject instanceof h)) {
      b(paramLong, paramString, paramObject);
    }
  }
  
  private void b(long paramLong, String paramString, Object paramObject)
  {
    h localh = (h)paramObject;
    i locali = new i();
    locali.b(localh.h());
    locali.a(localh.e());
    if (d.b()) {
      com.taobao.txc.common.a.a.a().c();
    }
    try
    {
      String str = localh.i() + ":" + localh.e();
      if ((this.e != null) && (this.e.b(localh.d())) && (this.b != null))
      {
        this.e.a(str, localh.h(), localh.d(), localh.b(), localh.f());
        locali.a(B.a.a());
        try
        {
          this.b.a(paramLong, paramString, locali);
        }
        catch (Throwable localThrowable1)
        {
          d.a("", "send response error", localThrowable1);
        }
      }
      else if ((this.c != null) && (this.a != null))
      {
        this.c.a(str, localh.h(), localh.d(), localh.b(), localh.f(), localh.g());
        locali.a(B.a.a());
        try
        {
          this.a.a(paramLong, paramString, locali);
          if (d.b()) {
            d.a("tran.branch.end", new Object[] { localh.i() + ":" + localh.e(), Long.valueOf(localh.h()), "rollback", Integer.valueOf(locali.a()), "1", Long.valueOf(com.taobao.txc.common.a.a.a().c()), "", "" });
          }
        }
        catch (Throwable localThrowable2)
        {
          d.a("", "send successful response error", localThrowable2);
          if (d.b()) {
            d.a("tran.branch.end", new Object[] { localh.i() + ":" + localh.e(), Long.valueOf(localh.h()), "rollback", Integer.valueOf(locali.a()), "0", Long.valueOf(com.taobao.txc.common.a.a.a().c()), "", localThrowable2.getMessage() });
          }
        }
      }
    }
    catch (Exception localException)
    {
      d.a(com.taobao.txc.common.b.b.T.bd, localException.getMessage(), localException);
      if ((localException instanceof c)) {
        locali.a(((c)localException).a());
      } else {
        locali.a(B.b.a());
      }
      locali.a(localException.getMessage());
      try
      {
        if ((this.e != null) && (this.e.b(localh.d())) && (this.b != null)) {
          this.b.a(paramLong, paramString, locali);
        } else if ((this.c != null) && (this.a != null)) {
          this.a.a(paramLong, paramString, locali);
        }
        if (d.b()) {
          d.a("tran.branch.end", new Object[] { localh.i() + ":" + localh.e(), Long.valueOf(localh.h()), "rollback", Integer.valueOf(locali.a()), "1", Long.valueOf(com.taobao.txc.common.a.a.a().c()), locali.b(), "" });
        }
      }
      catch (Throwable localThrowable3)
      {
        d.a("", "send failed response error", localThrowable3);
        if (d.b()) {
          d.a("tran.branch.end", new Object[] { localh.i() + ":" + localh.e(), Long.valueOf(localh.h()), "rollback", Integer.valueOf(locali.a()), "0", Long.valueOf(com.taobao.txc.common.a.a.a().c()), locali.b(), localThrowable3.getMessage() });
        }
      }
    }
  }
  
  private void c(long paramLong, String paramString, Object paramObject)
  {
    f localf = (f)paramObject;
    List localList1 = localf.g();
    List localList2 = localf.f();
    String str1 = localf.i();
    String str2 = localf.e();
    String str3 = localf.d();
    byte b1 = localf.h();
    String str4 = localf.b();
    a locala = null;
    Object localObject = null;
    if ((this.e != null) && (this.e.b(str2)) && (this.b != null))
    {
      locala = this.b;
      localObject = this.e;
    }
    else if ((this.c != null) && (this.a != null))
    {
      locala = this.a;
      localObject = this.c;
    }
    else
    {
      throw new RuntimeException("branch commit request IRmRpcClient is null!");
    }
    g localg = new g();
    localg.b(localList1);
    localg.a(localList2);
    try
    {
      for (int i = 0; i < localList1.size(); i++)
      {
        Long localLong1 = (Long)localList1.get(i);
        Long localLong2 = (Long)localList2.get(i);
        String str5 = str1 + ":" + localLong2;
        ((b)localObject).a(str5, localLong1.longValue(), str2, str3, b1, str4);
      }
      localg.a(B.a.a());
      locala.a(paramLong, paramString, localg);
    }
    catch (Exception localException)
    {
      d.a(com.taobao.txc.common.b.b.U.bd, localException.getMessage(), localException);
      localg.a(B.b.a());
      localg.a(localException.getMessage());
      locala.a(paramLong, paramString, localg);
    }
  }
  
  public void a(b paramb)
  {
    this.c = paramb;
  }
  
  public void a(a parama)
  {
    this.a = parama;
  }
  
  public void b(a parama)
  {
    this.b = parama;
  }
  
  public void a()
  {
    if (this.a != null) {
      this.a.a(this);
    }
    if (this.b != null) {
      this.b.a(this);
    }
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.j
 * JD-Core Version:    0.7.0.1
 */